﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace FacturIT.BLL.Model.Helper
{
    //public static class GenericPredicateBuilder
    //{
    //    public static Expression<Func<T, bool>> True<T>() { return f => true; }
    //    public static Expression<Func<T, bool>> False<T>() { return f => false; }

    //    public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
    //                                                        Expression<Func<T, bool>> expr2)
    //    {
    //        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
    //        return Expression.Lambda<Func<T, bool>>
    //              (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
    //    }

    //    public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
    //                                                         Expression<Func<T, bool>> expr2)
    //    {
    //        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
    //        return Expression.Lambda<Func<T, bool>>
    //              (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
    //    }


    //    //Te Controleren indien werkt
    //    //TODO
    //    //throw new NotImplementedException()
    //    public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> expr1)
    //    {
    //        var invokedExpr = Expression.Invoke(Expression.Not(expr1), expr1.Parameters.Cast<Expression>());

    //        return Expression.Lambda<Func<T, bool>>
    //              (invokedExpr, expr1.Parameters);
    //    }

    //    public static Expression<Func<TEntity, bool>> IsActive<TEntity>() where TEntity : IActive
    //    {
    //        return e => e.Active == true;
    //    }
    //    public static Expression<Func<TEntity, bool>> IsNotActive<TEntity>() where TEntity : IActive
    //    {
    //        return e => e.Active == false;
    //    }
    //}

    //public interface IPredicateBuilder<T>
    //{
    //    System.Linq.Expressions.Expression<Func<T, bool>> GenerateAndPredicate();
    //}
    public class PredicateGenerator<T> {
        //public static System.Linq.Expressions.Expression<Func<T, bool>> GenerateOrDatePredicate(DateTime[,] collection, Expression<Func<T, bool>> toUseOrExpression) 
        //{
        //    var tPredicate = GenericPredicateBuilder.True<T>();
        //    if (collection != null)
        //    {
        //        if (collection.Length > 0) tPredicate = GenericPredicateBuilder.False<T>();
        //        foreach (DateTime dt in collection)
        //        {
        //            DateTime temp = dt;
        //            tPredicate = tPredicate.Or(toUseOrExpression);
        //        }
        //    }
        //    return tPredicate;
        //}
        //public static System.Linq.Expressions.Expression<Func<T, bool>> GenerateOrIntPredicate()
        //{
        //}
        //public static System.Linq.Expressions.Expression<Func<T, bool>> GenerateOrStringPredicate()
        //{
        //}
        /*
         
         
         * 
         var idsPredicate = GenericPredicateBuilder.True<TicketPriority>();
            if (IDs != null)
            {
                if (IDs.Length > 0) idsPredicate = GenericPredicateBuilder.False<TicketPriority>();
                foreach (int id in IDs)
                {
                    int temp = id;
                    idsPredicate = idsPredicate.Or(p => p.TicketPriorityID.Equals(temp));
                }
            }
         * 
            var namesPredicate = GenericPredicateBuilder.True<TicketPriority>();
            if (Names != null)
            {
                if (Names.Length > 0) namesPredicate = GenericPredicateBuilder.False<TicketPriority>();
                foreach (string name in Names)
                {
                    string temp = name;
                    namesPredicate = namesPredicate.Or(p => p.Name.ToLower().Contains(temp));
                }
            }
         */
    }

    public interface IActive
    {
        bool Active { get; }
    }

}
